package com.qinglei.recoup.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.excel.poi.ExcelBoot;
import com.excel.poi.entity.ErrorEntity;
import com.excel.poi.function.ImportFunction;
import com.qinglei.recoup.common.domain.CommonRes;
import com.qinglei.recoup.common.service.impl.ProductCache;
import com.qinglei.recoup.common.tenant.TenantContextHolder;
import com.qinglei.recoup.common.utils.RecoupUtil;
import com.qinglei.recoup.system.dao.BedInformationMapper;
import com.qinglei.recoup.system.domain.*;
import com.qinglei.recoup.system.pojo.FileParam;
import com.qinglei.recoup.system.service.BedInformationService;
import com.qinglei.recoup.system.service.BedService;
import com.qinglei.recoup.system.service.DictService;
import com.qinglei.recoup.system.service.RadarService;
import com.qinglei.recoup.system.util.ExcelUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author dqh
 */
@Service
public class BedInformationServiceImpl extends ServiceImpl<BedInformationMapper, BedInformation> implements BedInformationService {


    @Autowired
    private DictService dictService;

    @Autowired
    private BedService bedService;


    @Value("${excel.path}")
    private String excelPath;

    @Autowired
    private RadarService radarService;

    @Autowired
    private ProductCache productCache;


    @Override
    public void addOrUpdate(BedInformation bedInformation) {
        if (bedInformation.getId() == null) {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("sn_code", bedInformation.getSnCode());
            BedInformation bedInformationOld = this.baseMapper.selectOne(queryWrapper);
            if (bedInformationOld != null) {
                throw new RuntimeException("设备" + bedInformation.getSnCode() + "已绑定！");
            }
        } else {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("sn_code", bedInformation.getSnCode());
            queryWrapper.ne("id", bedInformation.getId());
            BedInformation bedInformationOld = this.baseMapper.selectOne(queryWrapper);
            if (bedInformationOld != null) {
                throw new RuntimeException("设备" + bedInformation.getSnCode() + "已绑定！");
            }
        }

        bedInformation.setTenantId(RecoupUtil.getCurrentUser().getTenantId());
        this.saveOrUpdate(bedInformation);
    }

    @Override
    public BedInformation getByBedId(Integer bedId) {
        BedRadarBO bedRadarBO = bedService.getBedWithSn(bedId);
        if (bedRadarBO == null) {
            return null;
        }
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("sn_code", bedRadarBO.getSnCode());
        return this.baseMapper.selectOne(queryWrapper);
    }

    @Override
    public void deleteByBedId(Integer bedId) {
        BedRadarBO bedRadarBO = bedService.getBedWithSn(bedId);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("sn_code", bedRadarBO.getSnCode());
        this.baseMapper.delete(queryWrapper);
    }

    @Override
    public void deleteBySnCode(String snCode) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("sn_code", snCode);
        this.baseMapper.delete(queryWrapper);
    }

    @Override
    public CommonRes uploadFile(MultipartFile multipartFile, HttpServletRequest request) {
        InputStream inputStream = null;
        FileOutputStream fileOutputStream = null;
        String fileName = excelPath + "/" + UUID.randomUUID().toString() + ".xlsx";
        try {
            if (multipartFile.getOriginalFilename() == null || !ExcelUtil.isExcel(multipartFile.getOriginalFilename())) {
                return CommonRes.failed("仅支持xlsx格式文件");
            }
            inputStream = multipartFile.getInputStream();
            File file = new File(fileName);
            fileOutputStream = new FileOutputStream(file);
            byte[] bytes = new byte[100];
            while (inputStream.read(bytes) != -1) {
                fileOutputStream.write(bytes);
            }
        } catch (Exception e) {

        } finally {
            try {
                inputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("filePath", fileName);
        resultMap.put("message", "上传成功");
        return CommonRes.ok(resultMap);

    }

    @Override
    @Transactional
    public CommonRes importBedMsg(String filePath, Boolean isImport) {
        int index = 1;
        int error = 0;
        StringBuilder stringBuilder = new StringBuilder();
        Map<String, Object> resultMap = new HashMap<>();
        Workbook wb = null;
        Sheet sheet = null;
        Row row = null;
        List<Map<String, String>> list = null;
        String cellData = null;
        //SN号	姓名	性别	年龄段	行动能力	护理类别	呼吸1	呼吸2	心脏1	心脏2	是否失眠	是否打呼噜	起夜频次	呼吸暂停	慢阻肺	低通气	备注
        String columns[] = {"snCode", "name", "sex", "ageGroup", "actionAbility",
                "nursingLevel", "breath1", "breath2", "heart1", "heart2", "insomnia", "snore", "nightFrequency", "apnea", "copd", "Hypoventilation", "remarks"
        };

        String[] columnsZw = {"SN号", "姓名", "性别", "年龄段", "行动能力",
                "护理类别", "呼吸1", "呼吸2", "心脏1", "心脏2", "是否失眠", "是否打呼噜", "起夜频次", "呼吸暂停", "慢阻肺", "低通气", "备注"
        };
        wb = ExcelUtil.readExcel(filePath);
        if (wb != null) {
            //用来存放表中数据
            list = new ArrayList<Map<String, String>>();
            //获取第一个sheet
            sheet = wb.getSheetAt(0);
            //获取最大行数
            int rownum = sheet.getPhysicalNumberOfRows();
            if (rownum > 1001) {
                return CommonRes.failed("最大数据不能超过1000条");
            }
            //获取第一行
            row = sheet.getRow(0);

            //获取最大列数
            int colnum = row.getPhysicalNumberOfCells();
            //模版格式校验
            if(colnum != columnsZw.length){
                return CommonRes.failed("模版格式错误，请使用网站自带表格模版");
            }
            for (int i = 0; i < columnsZw.length; i++) {
                Cell cell = row.getCell(i);
                if (!columnsZw[i].equals(cell.getStringCellValue())) {
                    return CommonRes.failed("模版格式错误，请使用网站自带表格模版");
                }
            }
            for (int i = 1; i < rownum; i++) {
                Map<String, String> map = new LinkedHashMap<String, String>();
                row = sheet.getRow(i);
                if (row != null) {
                    for (int j = 0; j < colnum; j++) {
                        cellData = (String) ExcelUtil.getCellFormatValue(row.getCell(j));
                        //"3.0675133E7"

                        if (cellData.indexOf(".") > -1) {
                            BigDecimal bd = new BigDecimal(cellData);
                            cellData = bd.toPlainString();
                        }
                        if (StringUtils.isNotEmpty(cellData)) {
                            map.put(columns[j], cellData);
                        }
                    }
                } else {
                    break;
                }
                if (!map.isEmpty()) {
                    list.add(map);
                }
            }
        }

        List<String> radarOldErr = new ArrayList<>();
        List<String> existErr = new ArrayList<>();
        List<Integer> commError = new ArrayList<>();
        //遍历解析出来的list
        boolean isSave = true;
        for (Map<String, String> map : list) {
            index++;
            List<Integer> breathList = new ArrayList<>();
            List<Integer> heartList = new ArrayList<>();
            List<Integer> sleepDisorderedBreathingList = new ArrayList<>();
            BedInformation bedInformation = new BedInformation();

            for (Map.Entry<String, String> entry : map.entrySet()) {
                String paramName = entry.getKey();
                String paramValue = entry.getValue();
                boolean isParamNotBlank = StringUtils.isNotBlank(paramValue);
                if (isParamNotBlank) {
                    paramValue = paramValue.trim();
                }
                try {
                    // snCode:A123434TTR1,name:张三,sex:2-女,ageGroup:1-60岁以下,actionAbility:1-完全无法自理,nursingLevel:1-活力区,
                    // breath1:2-呼吸过缓,breath2:0-,heart1:1-心率过速,heart2:0-,insomnia:1-经常,snore:2-偶尔,nightFrequency:3-很少,
                    // apnea:1-有,copd:1-有,Hypoventilation:1-有,remarks:,
                    if (org.springframework.util.StringUtils.isEmpty(map.get("snCode"))) {
                        throw new RuntimeException();
                    }
                    if ("snCode".equals(paramName)) {
//                           Radar radarOld = radarService.selectOneNotTenant(paramValue);
                        boolean isExist = productCache.isExistEquipment(paramValue);
                        if (!isExist) {
                            existErr.add(paramValue);
                            error++;
                            isSave = false;
                            break;
                        }
                        BedInformation bedInformationOld = this.getByBedSnCode(paramValue);
                        bedInformation.setSnCode(paramValue);
                        if (bedInformationOld != null) {
                            radarOldErr.add(paramValue);
                            error++;
                        }
                    } else if ("name".equals(paramName) && isParamNotBlank) {
                        bedInformation.setName(paramValue);
                    } else if ("sex".equals(paramName) && isParamNotBlank) {
                        bedInformation.setSex(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("ageGroup".equals(paramName) && isParamNotBlank) {
                        bedInformation.setAgeGroup(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("actionAbility".equals(paramName) && isParamNotBlank) {
                        bedInformation.setActionAbility(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("nursingLevel".equals(paramName) && isParamNotBlank) {
                        bedInformation.setNursingLevel(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("breath1".equals(paramName) && isParamNotBlank) {
                        breathList.add(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("breath2".equals(paramName) && isParamNotBlank) {
//                        if (!breathList.contains(Integer.parseInt(paramValue.split("-")[0]))) {
//                            throw new RuntimeException();
//                        }
                        breathList.add(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("heart1".equals(paramName) && isParamNotBlank) {
                        heartList.add(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("heart2".equals(paramName) && isParamNotBlank) {
//                        if (!heartList.contains(Integer.parseInt(paramValue.split("-")[0]))) {
//                            throw new RuntimeException();
//                        }
                        heartList.add(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("insomnia".equals(paramName) && isParamNotBlank) {
                        bedInformation.setInsomnia(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("snore".equals(paramName) && isParamNotBlank) {
                        bedInformation.setSnore(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("nightFrequency".equals(paramName) && isParamNotBlank) {
                        bedInformation.setNightFrequency(Integer.parseInt(paramValue.split("-")[0]));
                    } else if ("apnea".equals(paramName) && isParamNotBlank) {
                        int tmp = Integer.parseInt(paramValue.split("-")[0]);
                        if (tmp == 1) {
                            sleepDisorderedBreathingList.add(1);
                        } else if (tmp == 2) {
                        } else {
                            throw new RuntimeException();
                        }

                    } else if ("copd".equals(paramName) && isParamNotBlank) {
                        int tmp = Integer.parseInt(paramValue.split("-")[0]);
                        if (tmp == 1) {
                            sleepDisorderedBreathingList.add(2);
                        } else if (tmp == 2) {
                        } else {
                            throw new RuntimeException();
                        }
                    } else if ("Hypoventilation".equals(paramName) && isParamNotBlank) {
                        int tmp = Integer.parseInt(paramValue.split("-")[0]);
                        if (tmp == 1) {
                            sleepDisorderedBreathingList.add(3);
                        } else if (tmp == 2) {
                        } else {
                            throw new RuntimeException();
                        }
                    } else if ("remarks".equals(paramName) && isParamNotBlank) {
                        bedInformation.setRemarks(paramValue);
                    }
                } catch (Exception e) {
                    log.error("---------", e);
                    e.printStackTrace();
                    error++;
                    commError.add(index);
                    isSave = false;
                    break;
                }
            }

            if (isImport) {
                if (isSave) {
                    if (breathList.size() > 0) {
                        bedInformation.setBreath(breathList.toString());
                    }
                    if (heartList.size() > 0) {
                        bedInformation.setHeart(heartList.toString());
                    }
                    if (sleepDisorderedBreathingList.size() > 0) {
                        bedInformation.setSleepDisorderedBreathing(sleepDisorderedBreathingList.toString());
                    }
                    Radar radarOld = radarService.selectOneNotTenant(bedInformation.getSnCode());
                    if (Objects.isNull(radarOld)) {
                        Radar radar = new Radar();
                        radar.setSnCode(bedInformation.getSnCode());
                        radarService.getBaseMapper().insert(radar);
                    }
                    bedInformation.setTenantId(RecoupUtil.getCurrentUser().getTenantId());
                    QueryWrapper queryWrapperTmp = new QueryWrapper();
                    queryWrapperTmp.eq("sn_code", bedInformation.getSnCode());
                    this.baseMapper.delete(queryWrapperTmp);
                    this.baseMapper.insert(bedInformation);
                } else {
                    StringBuilder stringBuilderB = new StringBuilder();
                    if (existErr.size() > 0) {
                        stringBuilderB.append("存在错误数据" + existErr.size() + "条");
                    }
                    if (commError.size() > 0) {
                        stringBuilderB.append("，存在格式问题数据" + commError.size() + "条");
                    }
                    return CommonRes.failed(stringBuilderB + "，导入失败");
                }
            }
        }
        resultMap.put("total", list.size());
        if (!isImport) {
            resultMap.put("repeatNum", radarOldErr.size());
            resultMap.put("invalid", existErr.size());
            resultMap.put("nonstandard", commError.size());
//            if (commError.size() > 0) {
//                stringBuilder.append("\n有以下" + commError.size() + "条数据不规范：#");
//                for (int i = 0; i < commError.size(); i++) {
//                    if (i == commError.size() - 1) {
//                        stringBuilder.append(commError.get(i) + "行");
//                    } else {
//                        stringBuilder.append(commError.get(i) + "行、");
//                    }
//                }

//            }
//            resultMap.put("msg", stringBuilder);
            resultMap.put("valid", list.size() - radarOldErr.size() - existErr.size() - commError.size());
            return CommonRes.ok(resultMap);
        }
        resultMap.put("msg", "导入成功");
        return CommonRes.ok(resultMap);
    }

    @Override
    public List<BedInfoMationDownDataVo> downProblemData(FileParam filePath) throws FileNotFoundException {
        List<BedInfoMationDownDataVo> bedInfoMationDownDataVoList = new ArrayList<>();
        ExcelBoot.ImportBuilder(new FileInputStream(new File(filePath.getFilePath())), BedInfoMationDownDataVo.class)
                .importExcel(new ImportFunction<BedInfoMationDownDataVo>() {
                    /**
                     * @param sheetIndex 当前执行的Sheet的索引, 从1开始
                     * @param rowIndex 当前执行的行数, 从1开始
                     */
                    @Override
                    public void onProcess(int sheetIndex, int rowIndex, BedInfoMationDownDataVo bedInfoMationDownDataVo) {
                        //将读取到Excel中每一行的userEntity数据进行自定义处理
                        //如果该行数据发生问题,将不会走本方法,而会走onError方法
                        bedInfoMationDownDataVoList.add(bedInfoMationDownDataVo);
                    }

                    /**
                     * @param errorEntity 错误信息实体
                     */
                    @Override
                    public void onError(ErrorEntity errorEntity) {
                        //将每条数据非空和正则校验后的错误信息errorEntity进行自定义处理
                    }
                });
        return this.downProblemDataHandle(bedInfoMationDownDataVoList);

    }


    //    @Override
    public List<BedInfoMationDownDataVo> downProblemDataHandle(List<BedInfoMationDownDataVo> bedInfoMationDownDataVoList) {
        List<BedInfoMationDownDataVo> problemList = new ArrayList<>();
        List<Integer> breathList = new ArrayList<>();
        List<Integer> heartList = new ArrayList<>();
        List<Integer> sleepDisorderedBreathingList = new ArrayList<>();
        for (BedInfoMationDownDataVo bedInfoMationDownDataVo : bedInfoMationDownDataVoList) {
            String paramValue = bedInfoMationDownDataVo.getSnCode();
            boolean isParamNotBlank = StringUtils.isNotBlank(paramValue);
            if (isParamNotBlank) {
                paramValue = paramValue.trim();
            }
            try {
                if (StringUtils.isEmpty(paramValue)) {
                    throw new RuntimeException();
                }
                boolean isExist = productCache.isExistEquipment(paramValue);
                if (!isExist) {
                    bedInfoMationDownDataVo.setErrorReason("SN号不存在");
                    problemList.add(bedInfoMationDownDataVo);   //2
                    continue;
                }
                BedInformation bedInformationOld = this.getByBedSnCode(paramValue);
                if (bedInformationOld != null) {
                    bedInfoMationDownDataVo.setErrorReason("重复数据");
                    problemList.add(bedInfoMationDownDataVo);   //1
                    continue;
                }
                //tttttttttt
                // snCode:A123434TTR1,name:张三,sex:2-女,ageGroup:1-60岁以下,actionAbility:1-完全无法自理,nursingLevel:1-活力区,
                // breath1:2-呼吸过缓,breath2:0-,heart1:1-心率过速,heart2:0-,insomnia:1-经常,snore:2-偶尔,nightFrequency:3-很少,
                BedInformation bedInformation = new BedInformation();
                bedInformation.setSex(Integer.parseInt(bedInfoMationDownDataVo.getSex().split("-")[0]));
                bedInformation.setAgeGroup(Integer.parseInt(bedInfoMationDownDataVo.getAgeGroup().split("-")[0]));
                bedInformation.setActionAbility(Integer.parseInt(bedInfoMationDownDataVo.getActionAbility().split("-")[0]));
                bedInformation.setNursingLevel(Integer.parseInt(bedInfoMationDownDataVo.getNursingLevel().split("-")[0]));
                breathList.add(Integer.parseInt(bedInfoMationDownDataVo.getBreath1().split("-")[0]));
                if (breathList.contains(Integer.parseInt(bedInfoMationDownDataVo.getBreath1().split("-")[0]))) {
                    throw new RuntimeException();
                }
                breathList.add(Integer.parseInt(bedInfoMationDownDataVo.getBreath2().split("-")[0]));
                heartList.add(Integer.parseInt(bedInfoMationDownDataVo.getHeart1().split("-")[0]));
                if (heartList.contains(Integer.parseInt(bedInfoMationDownDataVo.getHeart1().split("-")[0]))) {
                    throw new RuntimeException();
                }
                heartList.add(Integer.parseInt(bedInfoMationDownDataVo.getHeart2().split("-")[0]));
                bedInformation.setInsomnia(Integer.parseInt(bedInfoMationDownDataVo.getInsomnia().split("-")[0]));
                bedInformation.setSnore(Integer.parseInt(bedInfoMationDownDataVo.getSnore().split("-")[0]));
                bedInformation.setNightFrequency(Integer.parseInt(bedInfoMationDownDataVo.getNightFrequency().split("-")[0]));
                int tmp = Integer.parseInt(bedInfoMationDownDataVo.getHypoventilation().split("-")[0]);
                if (tmp == 1) {
                    sleepDisorderedBreathingList.add(1);
                } else if (tmp == 2) {
                } else {
                    throw new RuntimeException();
                }
                int tmp1 = Integer.parseInt(bedInfoMationDownDataVo.getHypoventilation().split("-")[0]);
                if (tmp1 == 1) {
                    sleepDisorderedBreathingList.add(2);
                } else if (tmp1 == 2) {
                } else {
                    throw new RuntimeException();
                }
                int tmp2 = Integer.parseInt(bedInfoMationDownDataVo.getHypoventilation().split("-")[0]);
                if (tmp2 == 1) {
                    sleepDisorderedBreathingList.add(3);
                } else if (tmp2 == 2) {
                } else {
                    throw new RuntimeException();
                }
                bedInformation.setRemarks(bedInfoMationDownDataVo.getRemarks());

            } catch (Exception e) {
                e.printStackTrace();
                bedInfoMationDownDataVo.setErrorReason("格式错误数据");
                problemList.add(bedInfoMationDownDataVo);   //3
                continue;
            }
        }
        return problemList;
    }

    @Override
    public BedInformation getByBedSnCode(String snCode) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("sn_code", snCode);
        return this.baseMapper.selectOne(queryWrapper);
    }

    @Override
    public CommonRes getAllBedInformationType() {
        List<DictBO> list = dictService.getDictItemList("bed_information");
        Map<String, Object> resultMap = new HashMap<>();
        List<Map<Long, Object>> sex = new ArrayList<>();
        List<Map<Long, Object>> age_group = new ArrayList<>();
        List<Map<Long, Object>> action_ability = new ArrayList<>();
        List<Map<Long, Object>> nursing_level = new ArrayList<>();
        List<Map<Long, Object>> breath = new ArrayList<>();
        List<Map<Long, Object>> heart = new ArrayList<>();
        List<Map<Long, Object>> insomnia = new ArrayList<>();
        List<Map<Long, Object>> snore = new ArrayList<>();
        List<Map<Long, Object>> night_frequency = new ArrayList<>();

        List<Map<Long, Object>> sleep_disordered_breathing = new ArrayList<>();

        list.forEach(t -> {
            if (t.getItemType().equals("sex")) {
                Map<Long, Object> sexItmp = new HashMap<>();
                sexItmp.put(t.getKeyy(), t.getValuee());
                sex.add(sexItmp);
            }

            if (t.getItemType().equals("age_group")) {
                Map<Long, Object> age_groupItmp = new HashMap<>();
                age_groupItmp.put(t.getKeyy(), t.getValuee());
                age_group.add(age_groupItmp);
            }


            if (t.getItemType().equals("action_ability")) {
                Map<Long, Object> action_abilityItmp = new HashMap<>();
                action_abilityItmp.put(t.getKeyy(), t.getValuee());
                action_ability.add(action_abilityItmp);
            }


            if (t.getItemType().equals("nursing_level")) {
                Map<Long, Object> nursing_levelItmp = new HashMap<>();
                nursing_levelItmp.put(t.getKeyy(), t.getValuee());
                nursing_level.add(nursing_levelItmp);
            }


            if (t.getItemType().equals("breath")) {
                Map<Long, Object> breathItmp = new HashMap<>();
                breathItmp.put(t.getKeyy(), t.getValuee());
                breath.add(breathItmp);
            }


            if (t.getItemType().equals("heart")) {
                Map<Long, Object> heartItmp = new HashMap<>();
                heartItmp.put(t.getKeyy(), t.getValuee());
                heart.add(heartItmp);
            }


            if (t.getItemType().equals("insomnia")) {
                Map<Long, Object> insomniaItmp = new HashMap<>();
                insomniaItmp.put(t.getKeyy(), t.getValuee());
                insomnia.add(insomniaItmp);
            }


            if (t.getItemType().equals("snore")) {
                Map<Long, Object> snoreItmp = new HashMap<>();
                snoreItmp.put(t.getKeyy(), t.getValuee());
                snore.add(snoreItmp);
            }


            if (t.getItemType().equals("night_frequency")) {
                Map<Long, Object> night_frequencyItmp = new HashMap<>();
                night_frequencyItmp.put(t.getKeyy(), t.getValuee());
                night_frequency.add(night_frequencyItmp);
            }

            if (t.getItemType().equals("sleep_disordered_breathing")) {
                Map<Long, Object> sleep_disordered_breathingItmp = new HashMap<>();
                sleep_disordered_breathingItmp.put(t.getKeyy(), t.getValuee());
                sleep_disordered_breathing.add(sleep_disordered_breathingItmp);
            }


            resultMap.put("sex", sex);
            resultMap.put("age_group", age_group);
            resultMap.put("action_ability", action_ability);
            resultMap.put("nursing_level", nursing_level);
            resultMap.put("breath", breath);
            resultMap.put("heart", heart);
            resultMap.put("insomnia", insomnia);
            resultMap.put("snore", snore);
            resultMap.put("night_frequency", night_frequency);
            resultMap.put("sleep_disordered_breathing", sleep_disordered_breathing);
        });

        return CommonRes.ok(resultMap);
    }


}
